export enum HeaderType {
    text = 'text',
    button = 'button',
    other = 'other'
}

export const tabMap = {
    '1': '公告',
    '2': '活动',
    '3': '车店',
    '4': '其他'
}

export function tabFormat(tab: string) {
    return tabMap[tab]
}

export function isEmpty(str: string) {
    return str === null || str.replace(/\s+/g, '') === ''
}

export function btnTypeFormatter(type: number) {
    switch (type) {
        case 1:
            return "primary";
        case 2:
            return "warning";
        case 3:
            return "success";
        case 4:
            return "danger";
    }
}

/**
 * 根据资源id获取资源url
 * 字段ID如果出现+ 会被URL解析成为空格
 * 需要先编码
 * @param resourceId
 * @returns {string}
 */
export function getUrlByResourceId(resourceId: string) {
    return '/apis/service/resource/file?id=' + encodeURIComponent(resourceId);
}

export function getYear(date: string) {
    let time = date.split('-')
    return time[0]
}

export function getMonthDay(date: string) {
    let time = date.split('-')
    return time[1] + '-' + time[2].split(' ')[0]
}

export function setLocalObj(key: string, obj: any) {
    localStorage.setItem(key, JSON.stringify(obj))
}

export function getLocalObj(key: string) {
    return JSON.parse(localStorage.getItem(key))
}

export function setLocalStr(key: string, str: string) {
    localStorage.setItem(key, str)
}

export function getLocalStr(key: string) {
    return localStorage.getItem(key)
}

export function setSessionObj(key: string, obj: any) {
    sessionStorage.setItem(key, JSON.stringify(obj))
}

export function getSessionObj(key: string) {
    return JSON.parse(sessionStorage.getItem(key))
}

export function setSessionStr(key: string, str: string) {
    sessionStorage.setItem(key, str)
}

export function getSessionStr(key: string) {
    return sessionStorage.getItem(key)
}

export function removeLocal(key: string) {
    localStorage.removeItem(key)
}

export function removeSession(key: string) {
    sessionStorage.removeItem(key)
}